package bb.lanxing.util;

import com.baidu.mapapi.model.LatLng;
import com.github.mikephil.charting.utils.Utils;
import bb.lanxing.lib.kt.model.geo.IGeoPoint;
import java.util.Arrays;
import java.util.List;

public class LocCountry {
    private static point[] pointsChongMing;
    private static point[] pointsHainan;
    private static point[] pointsHongkong;
    private static point[] pointsMainLand;
    private static point[] pointsTaiwan;

    public static class point {
        private double latitude;
        private double longitude;

        public point(double latitude, double longitude) {
            this.latitude = latitude;
            this.longitude = longitude;
        }

        public double getLatitude() {
            return this.latitude;
        }

        public void setLatitude(double latitude) {
            this.latitude = latitude;
        }

        public double getLongitude() {
            return this.longitude;
        }

        public void setLongitude(double longitude) {
            this.longitude = longitude;
        }
    }

    static {
        InitPolygon();
    }

    private static void InitPolygon() {
        pointsMainLand = new point[]{new point(27.32083d, 88.91693d), new point(27.54243d, 88.76464d), new point(28.00805d, 88.83575d), new point(28.1168d, 88.62435d), new point(27.86605d, 88.14279d), new point(27.82305d, 87.19275d), new point(28.11166d, 86.69527d), new point(27.90888d, 86.45137d), new point(28.15805d, 86.19769d), new point(27.88625d, 86.0054d), new point(28.27916d, 85.72137d), new point(28.30666d, 85.11095d), new point(28.59104d, 85.19518d), new point(28.54444d, 84.84665d), new point(28.73402d, 84.48623d), new point(29.26097d, 84.11651d), new point(29.18902d, 83.5479d), new point(29.63166d, 83.19109d), new point(30.06923d, 82.17525d), new point(30.33444d, 82.11123d), new point(30.385d, 81.42623d), new point(30.01194d, 81.23221d), new point(30.20435d, 81.02536d), new point(30.57552d, 80.207d), new point(30.73374d, 80.25423d), new point(30.96583d, 79.86304d), new point(30.95708d, 79.55429d), new point(31.43729d, 79.08082d), new point(31.30895d, 78.76825d), new point(31.96847d, 78.77075d), new point(32.24304d, 78.47594d), new point(32.5561d, 78.40595d), new point(32.63902d, 78.74623d), new point(32.35083d, 78.9711d), new point(32.75666d, 79.52874d), new point(33.09944d, 79.37511d), new point(33.42863d, 78.93623d), new point(33.52041d, 78.81387d), new point(34.06833d, 78.73581d), new point(34.35001d, 78.98535d), new point(34.6118d, 78.33707d), new point(35.28069d, 78.02305d), new point(35.49902d, 78.0718d), new point(35.50133d, 77.82393d), new point(35.6125d, 76.89526d), new point(35.90665d, 76.55304d), new point(35.81458d, 76.18061d), new point(36.07082d, 75.92887d), new point(36.23751d, 76.04166d), new point(36.66343d, 75.85984d), new point(36.73169d, 75.45179d), new point(36.91156d, 75.39902d), new point(36.99719d, 75.14787d), new point(37.02782d, 74.56543d), new point(37.17d, 74.39089d), new point(37.23733d, 74.91574d), new point(37.40659d, 75.18748d), new point(37.65243d, 74.9036d), new point(38.47256d, 74.85442d), new point(38.67438d, 74.35471d), new point(38.61271d, 73.81401d), new point(38.88653d, 73.70818d), new point(38.97256d, 73.85235d), new point(39.23569d, 73.62005d), new point(39.45483d, 73.65569d), new point(39.59965d, 73.95471d), new point(39.76896d, 73.8429d), new point(40.04202d, 73.99096d), new point(40.32792d, 74.88089d), new point(40.51723d, 74.8588d), new point(40.45042d, 75.23394d), new point(40.64452d, 75.58284d), new point(40.298d, 75.70374d), new point(40.35324d, 76.3344d), new point(41.01258d, 76.87067d), new point(41.04079d, 78.08083d), new point(41.39286d, 78.39554d), new point(42.03954d, 80.24513d), new point(42.19622d, 80.23402d), new point(42.63245d, 80.15804d), new point(42.81565d, 80.25796d), new point(42.88545d, 80.57226d), new point(43.02906d, 80.38405d), new point(43.1683d, 80.81526d), new point(44.11378d, 80.36887d), new point(44.6358d, 80.38499d), new point(44.73408d, 80.51589d), new point(44.90282d, 79.87106d), new point(45.3497d, 81.67928d), new point(45.15748d, 81.94803d), new point(45.13303d, 82.56638d), new point(45.43581d, 82.64624d), new point(45.5831d, 82.32179d), new point(47.20061d, 83.03443d), new point(46.97332d, 83.93026d), new point(46.99361d, 84.67804d), new point(46.8277d, 84.80318d), new point(47.0591d, 85.52257d), new point(47.26221d, 85.70139d), new point(47.93721d, 85.53707d), new point(48.39333d, 85.76596d), new point(48.54277d, 86.59791d), new point(49.1102d, 86.87602d), new point(49.09262d, 87.34821d), new point(49.17295d, 87.8407d), new point(48.98304d, 87.89291d), new point(48.88103d, 87.7611d), new point(48.73499d, 88.05942d), new point(48.56541d, 87.99194d), new point(48.40582d, 88.51679d), new point(48.21193d, 88.61179d), new point(47.99374d, 89.08514d), new point(47.88791d, 90.07096d), new point(46.95221d, 90.9136d), new point(46.57735d, 91.07027d), new point(46.29694d, 90.92151d), new point(46.01735d, 91.02651d), new point(45.57972d, 90.68193d), new point(45.25305d, 90.89694d), new point(45.07729d, 91.56088d), new point(44.95721d, 93.5547d), new point(44.35499d, 94.71735d), new point(44.29416d, 95.41061d), new point(44.01937d, 95.34109d), new point(43.99311d, 95.53339d), new point(43.28388d, 95.87901d), new point(42.73499d, 96.38206d), new point(42.79583d, 97.1654d), new point(42.57194d, 99.51012d), new point(42.67707d, 100.8425d), new point(42.50972d, 101.8147d), new point(42.23333d, 102.0772d), new point(41.88721d, 103.4164d), new point(41.87721d, 104.5267d), new point(41.67068d, 104.5237d), new point(41.58666d, 105.0065d), new point(42.46624d, 107.4758d), new point(42.42999d, 109.3107d), new point(42.64576d, 110.1064d), new point(43.31694d, 110.9897d), new point(43.69221d, 111.9583d), new point(44.37527d, 111.4214d), new point(45.04944d, 111.873d), new point(45.08055d, 112.4272d), new point(44.8461d, 112.853d), new point(44.74527d, 113.638d), new point(45.38943d, 114.5453d), new point(45.4586d, 115.7019d), new point(45.72193d, 116.2104d), new point(46.29583d, 116.5855d), new point(46.41888d, 117.3755d), new point(46.57069d, 117.425d), new point(46.53645d, 117.8455d), new point(46.73638d, 118.3147d), new point(46.59895d, 119.7068d), new point(46.71513d, 119.9315d), new point(46.90221d, 119.9225d), new point(47.66499d, 119.125d), new point(47.99475d, 118.5393d), new point(48.01125d, 117.8046d), new point(47.65741d, 117.3827d), new point(47.88805d, 116.8747d), new point(47.87819d, 116.2624d), new point(47.69186d, 115.9231d), new point(47.91749d, 115.5944d), new point(48.14353d, 115.5491d), new point(48.25249d, 115.8358d), new point(48.52055d, 115.8111d), new point(49.83047d, 116.7114d), new point(49.52058d, 117.8747d), new point(49.92263d, 118.5746d), new point(50.09631d, 119.321d), new point(50.33028d, 119.36d), new point(50.39027d, 119.1386d), new point(51.62083d, 120.0641d), new point(52.115d, 120.7767d), new point(52.34423d, 120.6259d), new point(52.54267d, 120.7122d), new point(52.58805d, 120.0819d), new point(52.76819d, 120.0314d), new point(53.26374d, 120.8307d), new point(53.54361d, 123.6147d), new point(53.18832d, 124.4933d), new point(53.05027d, 125.62d), new point(52.8752d, 125.6573d), new point(52.75722d, 126.0968d), new point(52.5761d, 125.9943d), new point(52.12694d, 126.555d), new point(51.99437d, 126.4412d), new point(51.38138d, 126.9139d), new point(51.26555d, 126.8176d), new point(51.31923d, 126.9689d), new point(51.05825d, 126.9331d), new point(50.74138d, 127.2919d), new point(50.31472d, 127.334d), new point(50.20856d, 127.5861d), new point(49.80588d, 127.515d), new point(49.58665d, 127.838d), new point(49.58443d, 128.7119d), new point(49.34676d, 129.1118d), new point(49.4158d, 129.4902d), new point(48.86464d, 130.2246d), new point(48.86041d, 130.674d), new point(48.60576d, 130.5236d), new point(48.3268d, 130.824d), new point(48.10839d, 130.6598d), new point(47.68721d, 130.9922d), new point(47.71027d, 132.5211d), new point(48.09888d, 133.0827d), new point(48.06888d, 133.4843d), new point(48.39112d, 134.4153d), new point(48.26713d, 134.7408d), new point(47.99207d, 134.5576d), new point(47.70027d, 134.7608d), new point(47.32333d, 134.1825d), new point(46.64017d, 133.9977d), new point(46.47888d, 133.8472d), new point(46.25363d, 133.9016d), new point(45.82347d, 133.4761d), new point(45.62458d, 133.4702d), new point(45.45083d, 133.1491d), new point(45.05694d, 133.0253d), new point(45.34582d, 131.8684d), new point(44.97388d, 131.4691d), new point(44.83649d, 130.953d), new point(44.05193d, 131.298d), new point(43.53624d, 131.1912d), new point(43.38958d, 131.3104d), new point(42.91645d, 131.1285d), new point(42.74485d, 130.4327d), new point(42.42186d, 130.6044d), new point(42.71416d, 130.2468d), new point(42.88794d, 130.2514d), new point(43.00457d, 129.9046d), new point(42.43582d, 129.6955d), new point(42.44624d, 129.3493d), new point(42.02736d, 128.9269d), new point(42.00124d, 128.0566d), new point(41.58284d, 128.3002d), new point(41.38124d, 128.1529d), new point(41.47249d, 127.2708d), new point(41.79222d, 126.9047d), new point(41.61176d, 126.5661d), new point(39.860951d, 124.312638d), new point(36.8270271807d, 122.6183135834d), new point(35.1004637138d, 120.2262980786d), new point(31.8962144634d, 123.7939453125d), new point(28.3527337602d, 122.3712158203d), new point(25.4779923206d, 120.3442382813d), new point(23.8004237024d, 118.9434814453d), new point(20.4733354977d, 116.9055175781d), new point(20.3170747288d, 110.5769729812d), new point(20.1664818843d, 110.2435204544d), new point(20.174019289d, 109.7344310096d), new point(20.792895d, 108.574731d), new point(21.54241d, 107.99d), new point(21.66694d, 107.7831d), new point(21.60526d, 107.3627d), new point(22.03083d, 106.6933d), new point(22.45682d, 106.5517d), new point(22.76389d, 106.7875d), new point(22.86694d, 106.7029d), new point(22.91253d, 105.8771d), new point(23.32416d, 105.3587d), new point(23.18027d, 104.9075d), new point(22.81805d, 104.7319d), new point(22.6875d, 104.3747d), new point(22.79812d, 104.1113d), new point(22.50387d, 103.9687d), new point(22.78287d, 103.6538d), new point(22.58436d, 103.5224d), new point(22.79451d, 103.3337d), new point(22.43652d, 103.0304d), new point(22.77187d, 102.4744d), new point(22.39629d, 102.1407d), new point(22.49777d, 101.7415d), new point(22.20916d, 101.5744d), new point(21.83444d, 101.7653d), new point(21.14451d, 101.786d), new point(21.17687d, 101.2919d), new point(21.57264d, 101.1482d), new point(21.76903d, 101.099d), new point(21.47694d, 100.6397d), new point(21.43546d, 100.2057d), new point(21.72555d, 99.97763d), new point(22.05018d, 99.95741d), new point(22.15592d, 99.16785d), new point(22.93659d, 99.56484d), new point(23.08204d, 99.5113d), new point(23.18916d, 98.92747d), new point(23.97076d, 98.67991d), new point(24.16007d, 98.89073d), new point(23.92999d, 97.54762d), new point(24.26055d, 97.7593d), new point(24.47666d, 97.54305d), new point(24.73992d, 97.55255d), new point(25.61527d, 98.19109d), new point(25.56944d, 98.36137d), new point(25.85597d, 98.7104d), new point(26.12527d, 98.56944d), new point(26.18472d, 98.73109d), new point(26.79166d, 98.77777d), new point(27.52972d, 98.69699d), new point(27.6725d, 98.45888d), new point(27.54014d, 98.31992d), new point(28.14889d, 98.14499d), new point(28.486789d, 97.620234d), new point(28.22277d, 97.34888d), new point(27.749839d, 97.084634d), new point(28.035903d, 96.551113d), new point(28.158267d, 96.035989d), new point(28.101181d, 95.566857d), new point(27.741654d, 95.14372d), new point(27.463014d, 94.371033d), new point(26.961314d, 93.901902d), new point(26.788071d, 93.147613d), new point(26.82109d, 92.098967d), new point(27.084894d, 92.025378d), new point(27.430185d, 92.006981d), new point(27.413767d, 91.685028d), new point(27.864356d, 91.390671d), new point(27.78257d, 91.114712d), new point(28.093023d, 89.882093d), new point(27.051953d, 89.091009d), new point(27.32083d, 88.91693d)};
        pointsHainan = new point[]{new point(20.1149080447d, 110.0236989119d), new point(20.2415828195d, 111.2200927734d), new point(18.7919177442d, 110.9344482422d), new point(17.821915516d, 109.4732666016d), new point(18.755511366d, 108.1658935547d), new point(20.0456108274d, 108.2867431641d)};
        pointsChongMing = new point[]{new point(31.80054d, 121.2039d), new point(31.49972d, 121.8736d), new point(31.53111d, 121.5464d), new point(31.80054d, 121.2039d)};
        pointsHongkong = new point[]{new point(22.50673d, 114.027343d), new point(22.506522d, 114.030118d), new point(22.506363d, 114.03177d), new point(22.506274d, 114.033969d), new point(22.505669d, 114.038507d), new point(22.50448d, 114.042037d), new point(22.503657d, 114.045277d), new point(22.501922d, 114.051832d), new point(22.501922d, 114.051832d), new point(22.502527d, 114.054064d), new point(22.517987d, 114.072824d), new point(22.529764d, 114.078633d), new point(22.536244d, 114.093308d), new point(22.52929d, 114.111898d), new point(22.543267d, 114.13842d), new point(22.541863d, 114.143992d), new point(22.542015d, 114.148821d), new point(22.546496d, 114.151815d), new point(22.550716d, 114.15121d), new point(22.552202d, 114.151907d), new point(22.554976d, 114.152186d), new point(22.554381d, 114.155791d), new point(22.561842d, 114.161477d), new point(22.559603d, 114.162947d), new point(22.55866d, 114.166517d), new point(22.553399d, 114.191538d), new point(22.555947d, 114.206176d), new point(22.552536d, 114.219591d), new point(22.54772d, 114.22634d), new point(22.547938d, 114.226726d), new point(22.545738d, 114.225342d), new point(22.544155d, 114.225996d), new point(22.532327d, 114.218246d), new point(22.535238d, 114.22965d), new point(22.541398d, 114.237909d), new point(22.548991d, 114.241668d), new point(22.550814d, 114.243031d), new point(22.556965d, 114.283311d), new point(22.558574d, 114.321873d), new point(22.509721d, 114.37311d), new point(22.435076d, 114.411575d), new point(22.421661d, 114.41083d), new point(22.153645d, 114.462324d), new point(22.134058d, 114.133094d), new point(22.138791d, 113.951936d), new point(22.194544d, 113.797265d), new point(22.396128d, 113.869698d), new point(22.431248d, 113.923444d), new point(22.493577d, 113.997836d), new point(22.488637d, 114.010574d), new point(22.487941d, 114.013682d), new point(22.485362d, 114.014643d), new point(22.485362d, 114.014643d), new point(22.485699d, 114.021896d), new point(22.490942d, 114.02092d), new point(22.49602d, 114.027896d), new point(22.50271d, 114.023869d), new point(22.506628d, 114.027469d)};
        pointsTaiwan = new point[]{new point(25.13474d, 121.4441d), new point(25.28361d, 121.5632d), new point(25.00722d, 122.0004d), new point(24.85028d, 121.8182d), new point(24.47638d, 121.8397d), new point(23.0875d, 121.3556d), new point(21.92791d, 120.7196d), new point(22.31277d, 120.6103d), new point(22.54044d, 120.3071d), new point(23.04437d, 120.0539d), new point(23.61708d, 120.1112d), new point(25.00166d, 121.0017d), new point(25.13474d, 121.4441d)};
    }

    private static boolean isInsidePolygon(point[] poly, double x, double y) {
        boolean z = false;
        point pointVar = poly[0];
        int i = 1;
        while (i < poly.length) {
            point pointVar2 = poly[i];
            if (y > Math.min(pointVar.latitude, pointVar2.latitude) && y <= Math.max(pointVar.latitude, pointVar2.latitude) && x <= Math.max(pointVar.longitude, pointVar2.longitude) && pointVar.latitude != pointVar2.latitude) {
                double d = (((y - pointVar.latitude) * (pointVar2.longitude - pointVar.longitude)) / (pointVar2.latitude - pointVar.latitude)) + pointVar.longitude;
                if (pointVar.longitude == pointVar2.longitude || x <= d) {
                    z = !z;
                }
            }
            i++;
            pointVar = pointVar2;
        }
        return z;
    }

    public static boolean IsWithIn(point point2, List<point> list) {
        double latitude;
        double longitude;
        double d;
        double d2;
        double latitude2 = point2.getLatitude();
        double longitude2 = point2.getLongitude();
        if (list.size() < 3) {
            return false;
        }
        int size = list.size();
        int i = 0;
        int i2 = 0;
        while (true) {
            int i3 = size - 1;
            if (i >= i3) {
                break;
            }
            if (i == i3) {
                latitude = list.get(i).getLatitude();
                longitude = list.get(i).getLongitude();
                d = list.get(0).getLatitude();
                d2 = list.get(0).getLongitude();
            } else {
                latitude = list.get(i).getLatitude();
                longitude = list.get(i).getLongitude();
                int i4 = i + 1;
                double latitude3 = list.get(i4).getLatitude();
                double longitude3 = list.get(i4).getLongitude();
                d = latitude3;
                d2 = longitude3;
            }
            if ((longitude2 >= longitude && longitude2 < d2) || (longitude2 >= d2 && longitude2 < longitude)) {
                double d3 = longitude - d2;
                if (Math.abs(d3) > Utils.DOUBLE_EPSILON && latitude - (((latitude - d) * (longitude - longitude2)) / d3) < latitude2) {
                    i2++;
                }
            }
            i++;
        }
        return i2 % 2 != 0;
    }

    public static boolean inChina(LatLng geoPoint, boolean includeTw) {
        if (geoPoint == null) {
            return false;
        }
        return includeTw ? isInChina(geoPoint) || inTW_HK(geoPoint) : isInChina(geoPoint);
    }

    public static boolean inChina(IGeoPoint geoPoint, boolean includeTw) {
        if (geoPoint == null) {
            return false;
        }
        LatLng latLng = new LatLng(geoPoint.getLatitude(), geoPoint.getLongitude());
        return includeTw ? isInChina(latLng) || inTW_HK(latLng) : isInChina(latLng);
    }

    public static boolean inTW_HK(LatLng geoPoint) {
        return isInTW(geoPoint) || isInHK(geoPoint);
    }

    public static boolean inTW_HK(IGeoPoint geoPoint) {
        LatLng latLng = new LatLng(geoPoint.getLatitude(), geoPoint.getLongitude());
        return isInTW(latLng) || isInHK(latLng);
    }

    public static boolean isInTW(LatLng geoPoint) {
        return IsWithIn(new point(geoPoint.latitude, geoPoint.longitude), Arrays.asList(pointsTaiwan));
    }

    public static boolean isInHK(LatLng geoPoint) {
        return IsWithIn(new point(geoPoint.latitude, geoPoint.longitude), Arrays.asList(pointsHongkong));
    }

    public static boolean isInChina(LatLng geoPoint) {
        return isInsidePolygon(pointsMainLand, geoPoint.longitude, geoPoint.latitude) || isInsidePolygon(pointsChongMing, geoPoint.longitude, geoPoint.latitude) || isInsidePolygon(pointsHainan, geoPoint.longitude, geoPoint.latitude);
    }
}